package cn.gok.day1;

/**
 * @ClassName 运算符
 * @Description TODO
 * @Author HP
 * @Date 14:26 2022/7/4
 * @Version 1.0
 **/
public class 运算符 {
    public static void main(String[] args) {
//        算数运算();
//        逻辑运算();
//        赋值运算();
        位运算();
    }

    private static void 位运算() {
        //运行速度最快
        int i=2|3;//按位或,00011
        int i2=2&3;//00010
        int i3=2^3;//00001
        int i4=~2;//-3
        System.out.println(i+" "+i2+""+i3+" "+i4);
        int i5=9>>2;//2
        int i6=9<<2;//36
        System.out.println(i5+" "+i6);
        int i7=(-7)>>2;
        int i8=(-7)<<3;
        System.out.println(i7+" "+i8);
    }

    private static void 赋值运算() {
        int i,j,k;
        i=j=k=10;
        int x;
        System.out.println(x=100);//对x赋值,返回100
        System.out.println(x==100);//返回false
        int x2=100;
        int x3;
//        x2+=2;
//        x2/=2;
//        x2++;
//        ++x2;
        System.out.println(-x2++);//-100
        System.out.println(x2);//101
        System.out.println(x3=-x2++);//-100
        System.out.println(x3=-++x2);//-101
    }

    private static void 逻辑运算() {
        int b=1;
        boolean b1=3<2&&b++>0;//短路
        System.out.println(b1);
    }

    private static void 算数运算() {
        //负号高于*/% 高于+ -
        int i=1+3*-4;
        int j=1+5%4*3;
        System.out.println(i+","+j);
        short s1=1+2;
        short s2=1;
        short s3=2;
        short s4=(short) (s2+s3);
        short s5=s2++;//自增不
    }
}
